<?
if (preg_match("#" . basename(__FILE__) . "#", $_SERVER['PHP_SELF'])) {
    die('This page cannot be called directly.');
}

class ajax_travel
{
    function playme()
    {

        $code = Url::getParam('code');
        //yêu cầu đặt tên $code=tên của method trong class
        if (method_exists($this, $code)) {
            $this->$code();
        } else {
            $this->home();
        }
    }

    function home()
    {
        global $display;
        die("Nothing to do...");
    }

    function loadTravel(){
        global $display;
        $ajax_response = new AjaxRes();
        $load = Url::getInt('load');
        if ($cat1 = DB::select('categories', 'set_default=1 AND status=1')) {
            $display->add('cat1_name', $cat1['name']);
            $display->add('cat1_id', $cat1['id']);
            $display->add('cat1_alias', $cat1['alias']);
            $load1 = $load+4;
            $load2 = $load+8;
            $load3 = $load+12;
            $sql_str1 = "SELECT t.* FROM news t WHERE FIND_IN_SET(" . $cat1['id'] . ", t.cate_ids) > 0 AND status=1 order by time_c desc limit ". $load1 . "," . $load2;
            $sql_str12 = "SELECT t.* FROM news t WHERE FIND_IN_SET(" . $cat1['id'] . ", t.cate_ids) > 0 AND status=1 order by time_c desc limit ". $load2 . "," . $load3;
            $news1 = DB::fetch_all($sql_str1);
            $news12 = DB::fetch_all($sql_str12);
            $end = (sizeof($news12) > 0) ? 0 : 1;
            if (sizeof($news1) > 0) {
                $ajax_response->end = $end;
                $imgsDefault1 = array();
                $newsShow1 = array();
                foreach ($news1 as $h1) {
                    if ($h1['img_url'] != '') {
                        $imgsDefault1[] = $h1['img_url'];
                        $newsShow1[] = $h1;
                    }
                }
                $imgsDefault1 = join(',', $imgsDefault1);
                $imgs1 = Db_Image::selectImages('id, img_name, img_url, img_server', '', "id IN ($imgsDefault1)");
                $display->add('imgs1', $imgs1);
                $display->add("news1", $newsShow1);
                $display->add("snews1", sizeof($newsShow1));
            }
            $result = $display->output('LoadTravel', true, 'Travel');
            $ajax_response->type = AjaxRes::SUCCESS;
            $ajax_response->item = $result;

        }else{
            $ajax_response->type = AjaxRes::SUCCESS;
            $ajax_response->item = '<br /><strong style="display: block;text-align: center;">Không có khách sạn nào</strong><br />';
        }
        echo $ajax_response->toString();
    }

    function loadTravelTwo(){
        global $display;
        $ajax_response = new AjaxRes();
        $load = Url::getInt('load');
        if ($cat2 = DB::select('categories', 'set_default=2 AND status=1')) {
            $display->add('cat2_name', $cat2['name']);
            $display->add('cat2_id', $cat2['id']);
            $display->add('cat2_alias', $cat2['alias']);
            $load1 = $load+10;
            $load2 = $load+20;
            $load3 = $load+30;
            $sql_str2 = "SELECT t.* FROM news t WHERE FIND_IN_SET(" . $cat2['id'] . ", t.cate_ids) > 0 AND status=1 order by time_c desc limit ". $load1 . "," . $load2;
            $sql_str22 = "SELECT t.* FROM news t WHERE FIND_IN_SET(" . $cat2['id'] . ", t.cate_ids) > 0 AND status=1 order by time_c desc limit ". $load2 . "," . $load3;
            $news2 = DB::fetch_all($sql_str2);
            $news22 = DB::fetch_all($sql_str22);
            $end = (sizeof($news22) > 0) ? 0 : 1;
            if (sizeof($news2) > 0) {
                $ajax_response->end = $end;
                $imgsDefault2 = array();
                $newsShow2 = array();
                foreach ($news2 as $h2) {
                    if ($h2['img_url'] != '') {
                        $imgsDefault2[] = $h2['img_url'];
                        $newsShow2[] = $h2;
                    }
                }
                $imgsDefault2 = join(',', $imgsDefault2);
                $imgs2 = Db_Image::selectImages('id, img_name, img_url, img_server', '', "id IN ($imgsDefault2)");
                $display->add('imgs2', $imgs2);
                $display->add("news2", $newsShow2);
                $display->add("snews2", sizeof($newsShow2));
            }
            $result = $display->output('LoadTravel2', true, 'Travel');
            $ajax_response->type = AjaxRes::SUCCESS;
            $ajax_response->item = $result;
        }else{
            $ajax_response->type = AjaxRes::SUCCESS;
            $ajax_response->item = '<br /><strong style="display: block;text-align: center;">Không có khách sạn nào</strong><br />';
        }
        echo $ajax_response->toString();
    }
}

?>